import {BASE_URL} from '@/api/config.js'
const request = (config) => {
	const show_msg=config.data&&config.data.show_msg;
	(config.data&&config.data.show_msg!=null)&&(delete config.data.show_msg);
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASE_URL + config.url,
			method: config.method || 'GET',
			data: config.data || {},
			header: { 
				"token": uni.getStorageSync('xxcstoken') || config.token
			},
			success: (res) => {
				if (res.data.code == 3 || res.data.code == -1||res.data.code==401) {
					uni.showToast({
						title: res.data.msg,
						icon: 'none'
					})
					setTimeout(() => {
						uni.navigateTo({
							url: '/pages/my/login'
						})
					}, 1000)
				}
				if(!config.err){
					if (res.data.code == 0 || (config.data && show_msg)) {
						if(res.data.msg!='加入失败'){
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							}) 
						}
						
					}
				}
				
				// console.log(JSON.stringify(res))
				resolve(res)
			},
			fail: (err) => {
				uni.hideLoading()
				console.log(err)
				reject(err)
			}
		})
	})
};
// 上传

export {
	request,
	BASE_URL
};